package main

import (
    "fmt"
    "strings"
)

func main() {
	//str:="abcdfdfdsfADASFDEWREFDS"
	//result := processLetter(str)
	//fmt.Println(result)
	//fmt.Println(StringToCase(str,processLetter))
	//fmt.Println(StringToCase2(str,processLetter))

	arr:=[]int{12,3,4,5,6,7,8,9,0,122,323,123,34,45,56,86,344,678,345,52}
	fmt.Println("slice=",arr)

	odd:=Filter(arr,isOdd)
	fmt.Println("奇数元素：",odd)

    even:=Filter(arr,isEven)
    fmt.Println("偶数元素：",even)
}

//deal string
func processLetter(str string) string{
    result := ""
    for i,value:=range str{
        if i%2 == 0{
            result += strings.ToUpper(string(value))
        }else {
            result += strings.ToLower(string(value))
        }
    }
    return result
}

//
func StringToCase(str string,myFunc func(string) string) string {
    return myFunc(str)
}


type caseFunc func(string) string

func StringToCase2(str string,myFunc caseFunc) string {
    return myFunc(str)
}



type myFunc func(int) bool

func isEven(num int) bool {
    if num%2==0{
        return true
    }else {
        return false
    }
}

func isOdd(num int) bool {
    if num%2==0{
        return false
    }else {
        return true
    }
}

func Filter(arr []int,f myFunc) []int {
    var result []int
    for _,value := range arr{
        if f(value){
            result = append(result,value)
        }
    }
    return result
}
